package cn.ichenkun.web.servlet;

import cn.ichenkun.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/StoreUserServlet")
public class StoreUserServlet extends HttpServlet {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");

        String sql = "insert into `user` (`name`,`email`,`phone`,`birthday`,`address`) value (?,?,?,?,?)";
        //2.执行sql
        template.update(sql, request.getParameter("name").toString(), request.getParameter("email").toString(), request.getParameter("phone").toString(), request.getParameter("birthday").toString(), request.getParameter("address").toString());

        //5.跳转到userListServlet
        request.getRequestDispatcher("/index.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
